package com.doit.mr.day06.yarn;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * @DATE 2021/12/8/16:54
 * @Author MDK
 * @Version 2021.2.2
 *   Mapper阶段
 *      MR内部处理数据是以KV形式处理的
 *      默认处理的文本文件
 *          KEYIN     输入的key    行的起始位置   Long
 *          VALUEIN   输入的value  行内容       String
 *          KEYOUT    输出的key    单词        String
 *          VALUEOUT  输出的value  次数        Integer
 *
 *    hdfs有自己的序列化机制  优化jdk的臃肿问题,数据量小  有利于大量数据持久化和网络传输
 *    Long-----LongWritable
 *    Integer---IntWritable
 *    String------Text
 *    Double-----DoubleWritable
 **/
public class WordCountMapper extends Mapper<LongWritable, Text, Text, IntWritable>{
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String line = value.toString();
        String[] words = line.split(" +");
        for (String word : words) {
            Text k = new Text(word);
            IntWritable v = new IntWritable(1);
            context.write(k,v);
        }
    }
}
